package org.nfIt.mapper;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Update;
import org.nfIt.entity.Article;

import java.util.List;

/**
 * ClossName:ArticleMapper
 * Pakage:org.nfIt.mapper
 * Description
 *
 * @Author L
 * @Create 2024/6/5 20:13
 * @Version 2023.1.3
 */
@Mapper
public interface ArticleMapper {
    /**
     * 添加文章
     * @param article 实体
     */
    @Insert("insert into article(title,content,cover_img,state,category_id,create_user,create_time,update_time) " +
            "values (#{title},#{content},#{coverImg},#{state},#{categoryId},#{createUser},#{createTime},#{updateTime})")
    void add(Article article);

    /**
     * 动态条件查询sql,使用映射文件
     * @param userid 用户id
     * @param categoryId  创建人ID
     * @param state 发布状态 已发布|草稿
     */
    List<Article> list(Integer userid, Integer categoryId, String state);

    @Update("update article set title=#{title},category_id=#{categoryId},cover_img=#{coverImg},content=#{content},state=#{state} where id=#{id}")
    void update(Article article);

    @Delete("delete from article where id=#{id}")
    void delete(Integer id);
}
